//
//  commCell.m
//  唧歪
//
//  Created by ZC on 15/9/5.
//  Copyright (c) 2015年 MWJ. All rights reserved.
//

#import "commCell.h"
#import "picbig.h"

@implementation commCell{
    UIImageView *img;
}


- (void)awakeFromNib {
    // Initialization code
    
    self.comment_Content.userInteractionEnabled = YES;
    [self.comment_Content addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(big)]];
    
    
    self.comment_Content.numberOfLines = 0;
    self.comment_Content.lineBreakMode = NSLineBreakByCharWrapping;
    [self messageAudio];
}
-(void)messageAudio{
    img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 1.5, 80, 20)];
    _wf = [[UIImageView alloc]initWithFrame:CGRectMake(5, 2.5, 15, 15)];
    img.userInteractionEnabled = YES;
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(audioplay)];
    [img addGestureRecognizer:singleTap];//点击图片事件
    _wf.image = [UIImage imageNamed:@"音量.png"];
    _lab = [[UILabel alloc]initWithFrame:CGRectMake(img.bounds.size.width-30, 2.5, 15, 15)];
    _lab.text = @"''";
    _lab.textAlignment = NSTextAlignmentRight;
    img.backgroundColor = [UIColor colorWithRed:252/255.0 green:208/255.0 blue:30/255.0 alpha:1];
    CALayer * layer = [img layer];
    [layer setCornerRadius:8.0];
    layer.borderColor = [[UIColor grayColor] CGColor];
    layer.borderWidth = 1;
    //添加四个边阴影
    img.layer.shadowColor = [UIColor blackColor].CGColor;
    img.layer.shadowOffset = CGSizeMake(0, 0);
    img.layer.shadowOpacity = 0.5;
    img.layer.shadowRadius = 10.0;
    //给iamgeview添加阴影 < wbr > 和边框
    //添加两个边阴影
    img.layer.shadowColor = [UIColor blackColor].CGColor;
    img.layer.shadowOffset = CGSizeMake(4, 4);
    img.layer.shadowOpacity = 0.5;
    img.layer.shadowRadius = 2.0;
    [img addSubview:_wf];
    [img addSubview:_lab];
    [self.audioview addSubview:img];
}
-(void)audioplay{
    NSLog(@"播放");
    if (self.avPlay.playing) {
        [self.avPlay stop];
        [self.wf stopAnimating];
        return;
    }else{
        NSLog(@"%@",self.audiourl);
        NSData *data = [NSData dataWithContentsOfURL:self.audiourl];
        AVAudioPlayer *player = [[AVAudioPlayer alloc]initWithData:data error:nil];
        self.avPlay = player;
        [self.avPlay prepareToPlay];
        [self.avPlay play];
        self.wf.animationImages = [NSArray arrayWithObjects:
                                   [UIImage imageNamed:@"音量.png"],
                                   [UIImage imageNamed:@"音量2.png"],
//                                   [UIImage imageNamed:@"wifi3.png"],
                                   nil];
        self.wf.animationDuration = 1.0;
        self.wf.animationRepeatCount = 0;
        [self.wf startAnimating];
        self.avPlay.delegate = self;
    }
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
    [self.wf stopAnimating];
}


-(void)big{
    if ([self.tagStr isEqualToString:@"1"]) {
        UIImageView *imageview = [[UIImageView alloc] initWithImage:self.image];
        [picbig showImage:imageview];
    }
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
